/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.uam.soi.converter;

import co.uam.soi.entity.Persona;
import co.uam.soi.session.PersonaFacade;
import co.uam.soi.session.PersonaFacadeLocal;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author hayner
 */
public class PersonaConverter implements Converter {
     
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Short id = null;
		try{
                PersonaFacadeLocal personaFacadeLocal= new PersonaFacade();
    		id = Short.valueOf(value);
                    System.out.println("da "+id);
                if(id!=null){
                   /* System.out.println("es "+personaFacadeLocal);
                    Persona persona = personaFacadeLocal.find(id);
                    return persona;*/
                    return id;
                }
    	}catch(Exception e){
            e.printStackTrace();
    		id = new Short("0");
    	}
		
        return id;//new Persona();
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value!=null){
            System.out.println("llego");
            try{
                return (String)value;//((Persona)value).getId().toString();
            }
            catch(Exception ex){}
        }
        return "";
    }

}
